package com.zyp.servlet;

import com.zyp.tool.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//班级的增删改查页面跳转
@WebServlet(name = "TheClassServlet",urlPatterns = "/theClassServlet")
public class TheClassServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取到前端传来的数据，获取到状态，为增删改查
        String strings = null;
        String add = request.getParameter("theClassAdd");
        if (add != null) {
            strings = Tool.CharacterConversion(add);
            response.sendRedirect("http://localhost:8081/task_5module_1/theClassAdd.jsp");
        }

        String inquire = request.getParameter("theClassInquire");
        if (inquire != null) {
            strings = Tool.CharacterConversion(inquire);
            //设置初始值
            Cookie cookie = new Cookie("yeshu", "0");
            response.addCookie(cookie);
            pagingQueryServlet pagingQueryServlet = new pagingQueryServlet();
            //调用后台，添加数据
            pagingQueryServlet.doPost(request, response);
        }

        String delete = request.getParameter("theClassDelete");
        if (delete != null) {
            strings = Tool.CharacterConversion(delete);
            response.sendRedirect("http://localhost:8081/task_5module_1/theClassdelete.jsp");
        }
        String update = request.getParameter("theClassUpdate");
        if (update != null) {
            strings = Tool.CharacterConversion(update);
            response.sendRedirect("http://localhost:8081/task_5module_1/theClassUpdate.jsp");
        }
        String main = request.getParameter("main");
        if (main != null) {
            strings = Tool.CharacterConversion(main);
            response.sendRedirect("http://localhost:8081/task_5module_1/main.jsp");
        }


        System.out.println(strings);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
